/**
 *  index.html 页面的javascript文件
 */

$().ready(function () {

    // ------------------------------------变量定义--------------------------------------
    var $serviceStatus = $("#service-status");
    var $bookNum = $("#book-num");
    var $maxNum = $("#max-num");
    var $departureDateTime = $("#departure-date-time");
    var $departureLocation = $("#departure-location");
    var $arriveLocation = $("#arrive-location");
    var $driverName = $("#driver-name");
    var $driverTelephone = $("#driver-tel");
    var $departureDate = $("#departure-date");
    var $departureDateDiv = $("#departure-date-div");
    var $baseInfoDiv = $("#base-info-div");
    var $testN1 = $("#test-n1");

    var departureDate; // 预订日期
    var timeMark; // 上午，下午标记
    var vehicleDeliveryId; // 车辆派送id
    var isAdmin; // 是否是管理员
    var isBook; // 是否预约
    var isEvaluation; // 是否评价
    var serviceDateTime;

    var shiftToVehicleDeliveryId = getUrlParam(); // 跳转回首页的vDId
    var shiftToFlag = 1; // 跳转标志

    var serviceStatusMap = {
        0 : "进行中",
        1 : "已结束",
        2 : "已取消"
    };
    // --------------------------页面的基本信息逻辑操作----------------------------------------------------

    getServiceDateTime(); // 获取服务器时间

    // ----------判断是否是跳转的----------
    if (shiftToVehicleDeliveryId !== null){
        // 表明是跳转回来的页面
        shiftToFlag = 0;
        getShiftToVehicleDeliveryInfo(shiftToVehicleDeliveryId);

    }else{
        // 表明不是从别的页面跳转回来
        // ----------执行一个laydate实例-直接嵌套显示----------
        laydate.render({
            elem: '#test-n1',
            position: 'static',
            showBottom: false,
            ready: function() {
                setTimeout(function(value) {
                    departureDate = $('.layui-this').attr('lay-ymd');
                    console.log(departureDate);

                    var dates = departureDate.split("-");
                    if(dates[1].length === 1){
                        dates[1] = "0" + dates[1]
                    }
                    if(dates[2].length === 1){
                        dates[2] = "0" + dates[2]
                    }
                    departureDate = dates.join("-");
                    console.log(departureDate);
                    // 显示到input中
                    $departureDate.text(departureDate);
                    // 去后台获取数据（根据日期和发车时间）
                    getVehicleDeliveryInfo(departureDate, timeMark);
                }, 100)

            },
            change: function(value) {
                departureDate = $('.layui-this').attr('lay-ymd');

                var dates = departureDate.split("-");
                if(dates[1].length === 1){
                    dates[1] = "0" + dates[1]
                }
                if(dates[2].length === 1){
                    dates[2] = "0" + dates[2]
                }
                departureDate = dates.join("-");
                console.log(departureDate);
                // 显示到input中
                $departureDate.text(departureDate);
                // 1. 将时间控件隐藏， 显示日期输入框
                $testN1.hide(100);
                setTimeout(function(){
                    $departureDateDiv.show();
                    // 2. 将基本信息页面上拉
                    $baseInfoDiv.removeClass("base-info-div");
                }, 100);
                // 去后台获取数据（根据日期和发车时间）
                console.log("点击 ： " + departureDate);
                $("#book-users").empty();
                getVehicleDeliveryInfo(departureDate, timeMark);
            }
        });
    }

    // ----------跳转后的页面进入，否则跳过----------
    if (shiftToFlag === 0){
        // ----------执行一个laydate实例-直接嵌套显示----------
        laydate.render({
            elem: '#test-n1',
            position: 'static',
            showBottom: false,

            change: function(value) {
                departureDate = $('.layui-this').attr('lay-ymd');

                var dates = departureDate.split("-");
                if(dates[1].length === 1){
                    dates[1] = "0" + dates[1]
                }
                if(dates[2].length === 1){
                    dates[2] = "0" + dates[2]
                }
                departureDate = dates.join("-");
                console.log(departureDate);
                // 显示到input中
                $departureDate.text(departureDate);
                // 1. 将时间控件隐藏， 显示日期输入框
                $testN1.hide(100);
                setTimeout(function(){
                    $departureDateDiv.show();
                    // 2. 将基本信息页面上拉
                    $baseInfoDiv.removeClass("base-info-div");
                }, 100);
                // 去后台获取数据（根据日期和发车时间）
                console.log("点击 ： " + departureDate);
                $("#book-users").empty();
                getVehicleDeliveryInfo(departureDate, timeMark);
            }
        });
    }

    // ----------根据当前时间来设置select选项serviceDateTime----------
    var $myDate = new Date();
    if ($myDate.getHours() >= 12){
        // 下午
        // $('#selectOption').find('option[value="2"]').attr("selected",true);  在ios上不起作用，prop是可以的
        // $('#selectOption').find('option[value="2"]').prop("selected",true);
        $('#selectOption').val("2");
        console.log("下午");
        timeMark = 2;
    }else {
        // 上午
        // $('#selectOption').find('option[value="1"]').prop("selected",true);
        $('#selectOption').val("1");
        console.log("上午");
        timeMark = 1;
    }

    // ----------上下午选择----------
    $('#selectOption').change(function(){
        // 这步主要是获取对应类别的商品列表
        timeMark = $('#selectOption').val();
        console.log(timeMark);
        if(timeMark === "0"){
            // 提示用户
            $("#dialog1 .weui-dialog__title").html("请选择“上午”或者“下午”进行预约！");
            $("#dialog1").show();
        }else {
            // 去后台获取数据（根据日期和发车时间）
            console.log("select ： " + $('.layui-this').attr('lay-ymd'));
            var dates =  $('.layui-this').attr('lay-ymd').split("-");
            if(dates[1].length === 1){
                dates[1] = "0" + dates[1]
            }
            if(dates[2].length === 1){
                dates[2] = "0" + dates[2]
            }
            var _departureDate = dates.join("-");
            console.log(_departureDate);
            getVehicleDeliveryInfo(_departureDate, timeMark);
        }
    });

    // ----------body上划事件-----------
    // 默认加上
    $baseInfoDiv.addClass("base-info-div-1");
    $("body").swipe({
        swipe : function (event, direction, distance, duration, fingerCount) {
            if (direction === "up"){
                console.log("我上滑了！！！！！");
                $testN1.hide(100);
                setTimeout(function(){
                    $departureDateDiv.show();
                    // 2. 将基本信息页面上拉
                    $baseInfoDiv.removeClass("base-info-div");
                    $baseInfoDiv.addClass("base-info-div-1");
                }, 100);
            } else if(direction === "down"){
                console.log("我下滑了！！！！！");
                $testN1.show(100);
                $departureDateDiv.hide();
                // 2. 将基本信息页面往下推
                $baseInfoDiv.removeClass("base-info-div-1");
                $baseInfoDiv.addClass("base-info-div");
            }

        }
    });

    // ----------发车日期点击操作----------
    $departureDateDiv.on("click", function () {

        // 1. 点击后显示日历控件, 隐藏发车日期输入框
        // $testN1.show(100) 比 fadeIn(100);更有渐变效果
        $testN1.show(100);
        $departureDateDiv.hide();
        // 2. 将基本信息页面往下推
        $baseInfoDiv.addClass("base-info-div");
    });


    // ----------用户预约----------
    $("#my-book").on("click", function () {
        if ($serviceStatus.html() === "进行中") {
            window.location.href = './htm/bookInfo.html?vehicleDeliveryId='+vehicleDeliveryId;
        }else if ($serviceStatus.html() === "已结束" ) {
            $("#dialog .weui-dialog__title").html("该服务已结束，不可以预约哦！");
            $("#dialog").show();
        }else {
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以预约哦！");
            $("#dialog").show();
        }
    });
    $("#book-user").on("click", function () {
        if ($serviceStatus.html() === "进行中") {
            window.location.href = './htm/bookInfo.html?vehicleDeliveryId='+vehicleDeliveryId;
        }else if ($serviceStatus.html() === "已结束" ) {
            $("#dialog .weui-dialog__title").html("该服务已结束，不可以预约哦！");
            $("#dialog").show();
        }else {
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以预约哦！");
            $("#dialog").show();
        }
    });
    // ----------编辑/取消报名----------
    $("#edit-or-cancel").on("click", function () {
        if ($serviceStatus.html() === "进行中") {
            window.location.href = './htm/bookInfo.html?vehicleDeliveryId='+vehicleDeliveryId;
        }else if ($serviceStatus.html() === "已结束" ) {
            $("#dialog .weui-dialog__title").html("该服务已结束，不可以编辑/取消哦！");
            $("#dialog").show();
        }else {
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以编辑/取消哦！");
            $("#dialog").show();
        }
    });
    $("#edit-or-cancel-manage").on("click", function () {
        if ($serviceStatus.html() === "进行中") {
            window.location.href = './htm/bookInfo.html?vehicleDeliveryId='+vehicleDeliveryId;
        }else if ($serviceStatus.html() === "已结束" ) {
            $("#dialog .weui-dialog__title").html("该服务已结束，不可以编辑/取消哦！");
            $("#dialog").show();
        }else {
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以编辑/取消哦！");
            $("#dialog").show();
        }
    });
    // ----------点击评价本次服务----------
    $("#add").on("click", function () {
        // 如果司机信息不为空
        if ($("#driverInfo").text() === ""){
            //提示
            $("#dialog .weui-dialog__title").html("司机信息为空，不能评价本次服务！");
            $("#dialog").show();
        }else {
            if ($serviceStatus.html() === "进行中") {

                $("#dialog .weui-dialog__title").html("该服务还未开始，不可以点击评价本次服务哦！");
                $("#dialog").show();
            }else if ($serviceStatus.html() === "已结束" ) {
                window.location.href = './htm/serviceEvaluation.html?vehicleDeliveryId='+vehicleDeliveryId;
            }else {
                $("#dialog .weui-dialog__title").html("该服务已取消，不可以点击评价本次服务哦！");
                $("#dialog").show();
            }
        }

    });
    $("#add-manage").on("click", function () {

        // 如果司机信息不为空
        if ($("#driverInfo").text() === ""){
            //提示
            $("#dialog .weui-dialog__title").html("司机信息为空，不能进行导出操作！");
            $("#dialog").show();
        }else {
            if ($serviceStatus.html() === "进行中") {
                $("#dialog .weui-dialog__title").html("该服务还未结束，不可以点击评价本次服务哦！");
                $("#dialog").show();
            }else if ($serviceStatus.html() === "已结束" ) {
                window.location.href = './htm/serviceEvaluation.html?vehicleDeliveryId='+vehicleDeliveryId;
            }else {
                $("#dialog .weui-dialog__title").html("该服务已取消，不可以点击评价本次服务哦！");
                $("#dialog").show();
            }
        }

    });
    // ----------点击查看服务评价----------
    $("#look-over").on("click", function () {
        if ($serviceStatus.html() === "进行中") {
            $("#dialog .weui-dialog__title").html("该服务还未开始，不可以点击评价本次服务哦！");
            $("#dialog").show();
        }else if ($serviceStatus.html() === "已结束" ) {
            window.location.href = './htm/serviceEvaluation.html?vehicleDeliveryId='+vehicleDeliveryId;
        }else {
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以点击评价本次服务哦！");
            $("#dialog").show();
        }
    });
    $("#look-over-manage").on("click", function () {
        if ($serviceStatus.html() === "进行中") {
            $("#dialog .weui-dialog__title").html("该服务还未开始，不可以点击评价本次服务哦！");
            $("#dialog").show();
        }else if ($serviceStatus.html() === "已结束" ) {
            window.location.href = './htm/serviceEvaluation.html?vehicleDeliveryId='+vehicleDeliveryId;
        }else {
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以点击评价本次服务哦！");
            $("#dialog").show();
        }
    });

    // ----------以下为系统管理员专有----------
    // ----------系统管理员----------
    $("#system-manage").on('click', function () {
        $("#mask").show();
        $("#manage-div").show();

    });
    $("#system-manage2").on('click', function () {
        $("#mask").show();
        $("#manage-div").show();

    });
    $("#system-manage3").on('click', function () {
        $("#mask").show();
        $("#manage-div").show();

    });
    $("#system-manage4").on('click', function () {
        $("#mask").show();
        $("#manage-div").show();

    });

    // ----------隐藏弹出的div----------
    $("#cancel").on('click', function () {
        $("#system-manage").show();
        $("#manage-div").hide();
        $("#mask").hide();
    });

    // ----------管理员编辑----------
    $("#edit").on("click", function () {
        if ($serviceStatus.html() === "进行中") {
            window.location.href = './htm/editShuttleBusInfo.html?vehicleDeliveryId='+vehicleDeliveryId;
        }else if ($serviceStatus.html() === "已结束" ) {
            $("#dialog .weui-dialog__title").html("该服务已结束，不可以编辑哦！");
            $("#dialog").show();
        }else {
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以编辑哦！");
            $("#dialog").show();
        }
    });

    // ----------数据导出----------
    $("#export-data").on("click", function () {
        // 如果司机信息不为空
        if ($("#driverInfo").text() === ""){
            //提示
            $("#dialog .weui-dialog__title").html("司机信息为空，不能进行导出操作！");
            $("#dialog").show();
        }else if ($("#book-users .weui-cell").length === 0) {
            //提示
            $("#dialog .weui-dialog__title").html("没有用户进行预约，不能进行导出操作！");
            $("#dialog").show();
        }else {
            window.location.href = './htm/exportData.html?vehicleDeliveryId='+vehicleDeliveryId;
        }

    });

    // ----------发送通知----------
    $("#send-message").on("click", function () {
        console.log($serviceStatus.html());
        if ($serviceStatus.html() === "已取消"){
            //提示
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以发送通知哦！");
            $("#dialog").show();
        } else {
            if (isPastDue()){
                window.location.href = './htm/sendMessage.html?vehicleDeliveryId='+vehicleDeliveryId;
            } else {
                // 提示班车出发时间已过
                $("#dialog .weui-dialog__title").html("发送通知时间不可晚于班车发车时间哦！");
                $("#dialog").show();
            }
        }

    });

    // ----------取消服务----------
    $('#cancel-service').on("click", function () {
        if ($serviceStatus.html() === "进行中") {
            $("#cancelDialog").show();
        }else if ($serviceStatus.html() === "已结束") {
            $("#dialog .weui-dialog__title").html("该服务已结束，不可以取消哦！");
            $("#dialog").show();
        }else {
            $("#dialog .weui-dialog__title").html("该服务已取消，不可以取消哦！");
            $("#dialog").show();
        }

    });

    // ----------toast Dialog 操作----------
    $("#iknow").on("click", function () {
        $("#dialog").hide();
    });
    $("#iknow1").on("click", function () {
        $("#dialog").hide();
        window.location.reload();
    });

    $("#cancelNo").on("click", function () {

        $("#cancelDialog").hide();
    });

    $("#cancelYes").on("click", function () {
        $("#cancelDialog").hide();
        $("#manage-div").hide();
        $("#system-manage").show();
        $("#loadingToast .weui-toast__content").text("取消服务中");
        $("#loadingToast").fadeIn(100);
        $.post("/bcs/manage/closeService", {"vehicleDeliveryId": vehicleDeliveryId},
            function (result) {
                if (result.manageResult.errcode === 0){
                    console.log("取消成功");
                    $("#loadingToast").hide();
                    $("#toast .weui-toast__content").text("取消成功");
                    $("#toast").fadeIn(100);
                    setTimeout(function(){
                        $("#toast").fadeOut(100);
                    }, 2000);

                    var dates =  $('.layui-this').attr('lay-ymd').split("-");
                    if(dates[1].length === 1){
                        dates[1] = "0" + dates[1]
                    }
                    if(dates[2].length === 1){
                        dates[2] = "0" + dates[2]
                    }
                    var _departureDate = dates.join("-");
                    console.log(_departureDate);
                    getVehicleDeliveryInfo(_departureDate, timeMark);
                    $("#mask").hide();

                } else {
                    $("#loadingToast").hide();
                    $("#toast .weui-toast__content").text("取消失败");
                    $("#toast").fadeIn(100);
                    setTimeout(function(){
                        $("#toast").fadeOut(100);
                    }, 2000);
                }
            });

    });

    // ----------根据其他页面跳转过来的vDId回显信息getBaseInfoByVehicleDeliveryId----------
    function getShiftToVehicleDeliveryInfo(vehicleDeliveryId) {
        // 根据VehicleDeliveryId获取车辆派送id
        $.get("/bcs/manage/getBaseInfoByVehicleDeliveryId?vehicleDeliveryId=" + vehicleDeliveryId, function (result) {
            if (result.manageResult.errcode === 0){
                var targetData = result.manageResult.data;
                var shiftToDepartureDate = targetData.departureDate;
                var shiftToTimeMark = targetData.timeMark;

                $departureDate.text(shiftToDepartureDate);

                // 根据timeMark指定上下午
                if (shiftToTimeMark === "1" || shiftToTimeMark === 1){
                    $('#selectOption').find('option[value="1"]').prop("selected",true);
                } else {
                    $('#selectOption').find('option[value="2"]').prop("selected",true);
                }
                getVehicleDeliveryInfo(shiftToDepartureDate, shiftToTimeMark);
            }
        });
    }

    // ----------首次进入页面时，获取车辆派送信息----------
    function getVehicleDeliveryInfo(departureDate, timeMark) {

        // 清空已渲染的数据
        $("#book-users").empty();
        $serviceStatus.empty();
        $bookNum.empty();
        $maxNum.empty();
        $departureDateTime.empty();
        $departureLocation.empty();
        $arriveLocation.empty();
        $("#driverInfo").empty();

        $.get("/bcs/manage/getBaseInfoByDepartureDateAndTimeMark?departureDate=" + departureDate +"&timeMark="+timeMark,
            function (result) {
                console.log(result);
                if (result.manageResult.errcode === 0){
                    var targetData = result.manageResult.data;
                    // 给vehicleDeliveryId赋值
                    vehicleDeliveryId = targetData.vehicleDeliveryId;
                    getRole();
                    // 将获取的信息渲染到页面上
                    // 根据返回的状态显示不同的颜色
                    // color: #888888; stop
                    // color: #0BB20C running
                    // color: #ff1022 cancel
                    if (serviceStatusMap[targetData.serviceStatus] === "进行中") {
                        $("#service-status-div").css("color", "#0BB20C");
                    }else if (serviceStatusMap[targetData.serviceStatus] === "已结束") {
                        $("#service-status-div").css("color", "#888888");
                    }else {
                        $("#service-status-div").css("color", "#ff1022");
                    }
                    $serviceStatus.text(serviceStatusMap[targetData.serviceStatus]);
                    $bookNum.text(targetData.bookNum);
                    if (targetData.maxNum > 0){
                        $maxNum.text(targetData.maxNum);
                    } else {
                        $maxNum.text("无限制");
                    }
                    $departureDateTime.text(targetData.departureDate +" "+targetData.departureTime);
                    $departureLocation.text(targetData.departureLocation);
                    $arriveLocation.text(targetData.arriveLocation);
                    // 渲染司机信息
                    var driverList = targetData.driverInfoVoList;
                    var driverHtml = '';
                    if (driverList !== null){
                        for (var i=0; i<driverList.length; i++){
                            driverHtml += '<div class="weui-cell my-weui-cell"><div class="weui-cell__hd"><label class="weui-label">';
                            driverHtml += '<i class="fa " style="font-size: 28px; width: 28px"></i>&nbsp;&nbsp;' + driverList[i].driverName;
                            driverHtml += '</label></div><div class="weui-cell__bd"><span>';
                            driverHtml += '<a href="tel://'+ driverList[i].driverTelephone +'">'+ driverList[i].driverTelephone +'</a>';
                            driverHtml += '</span></div></div>';
                        }
                        $("#driverInfo").html(driverHtml);
                    }

                    // 获取用户信息列表
                    bookUsers(vehicleDeliveryId)
                }else {
                    console.log("没有当前时间点的服务！");
                    // 提示
                    $("#dialog1 .weui-dialog__title").html("预约服务周期只限当前时间起15天内！");
                    $("#dialog1").show();

                }
            });
    }

    function isIOS() {
        var u = navigator.userAgent;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

        if (isiOS){
            // ios 系统
            return true;
        }else {
            return false;
        }
    }

    // 获取报名成功的用户信息 后续分页使用
    // function bookUsers(bookDate, departureTime, pageNo, pageSize){
    //
    //     $.get("url", {"bookDate" : bookDate, "bookTime" : departureTime,"pageNo" : pageNo, "pageSize" : pageSize},
    //         function (result) {
    //
    //         })
    // }

    // ----------获取报名成功的用户信息----------
    function bookUsers(vehicleDeliveryId){

        $.get("/bcs/user/getBookUserList?vehicleDeliveryId=" + vehicleDeliveryId,
            function (result) {
                console.log(result);
                // 根据结果调用joinHtml()
                if (result.bookResult.errcode === 0){
                    var targetData = result.bookResult.data;
                    // 设置报名人数
                    $bookNum.empty();
                    $bookNum.text(targetData.length);
                    var html = '';
                    for (var i=targetData.length - 1; i>=0; i--){
                        var no = targetData.length - i;
                        console.log(targetData[i].user_name);
                        html += '<div class="weui-cell"><div class="weui-cell__hd" style="position: relative;margin-right: 10px;">';

                        if (targetData.avatar === "kong"){
                            // 获取图像链家显示为空则使用默认图像
                            html += '<img src="images/meinv_02.jpg" style="width: 50px;display: block"></div>';
                        } else {
                            // 使用企业微信图像
                            html += '<img src="'+ targetData[i].avatar +'" style="width: 50px;display: block"></div>';
                        }

                        html += '<div class="weui-cell__bd"><p><span id="user-name-"'+ i +'>'+ targetData[i].userName +'</span>&nbsp;&nbsp;';
                        html += '<span id="user-tel"'+i+'>'+ targetData[i].userTelephone +'</span></p>';
                        html += '<p style="font-size: 13px;color: #888888;"><span id="book-date-time-"' + i + '>'+ targetData[i].createTime +'</span></p></div>';
                        html += '<div class="weui-cell__ft"><p>报名成功</p><p style="font-size: 13px;color: #888888;">';

                        if (targetData[i].agent !== "空"){
                            html += '<span class="agent-span" >[</span><span class="agent-span" >代</span><span class="agent-span" >]</span>&nbsp;&nbsp;';
                        }
                        html += '<span>No.</span><span id="book-rank">'+no+'</span></p></div></div>';
                    }

                    // 渲染到页面
                    $("#book-users").html(html);
                }
            })
    }

    // ----------获取用户信息----------
    function getRole() {
        $.get("/bcs/user/getUserBaseInfo?vehicleDeliveryId=" + vehicleDeliveryId, function (result) {
            console.log(result);
            if (result.bookResult.errcode === 0){
                var targetData = result.bookResult.data;
                isAdmin = targetData.isAdmin;
                isBook = targetData.isBook;
                isEvaluation = targetData.isEvaluation;
                if (isAdmin === 0){
                    // 表示是管理员
                    $("#manage").show();
                    $("#user").hide();
                    // 是否预约
                    if (isBook === 0){
                        // 已预约
                        $("#one-manage").hide();
                        $("#tow-manage").show();
                        $("#three-manage").hide();
                        $("#four-manage").hide();
                        // 是否评价
                        if (isEvaluation === 0){
                            // 已评价
                            $("#one-manage").hide();
                            $("#tow-manage").hide();
                            $("#three-manage").hide();
                            $("#four-manage").show();
                        } else {
                            // 未评价
                            $("#one-manage").hide();
                            if (isPastDue()) {
                                $("#tow-manage").show();
                                $("#three-manage").hide();
                            }else {
                                $("#tow-manage").hide();
                                $("#three-manage").show();
                            }
                            $("#four-manage").hide();
                        }
                    } else {
                        // 未预约
                        $("#one-manage").show();
                        $("#tow-manage").hide();
                        $("#three-manage").hide();
                        $("#four-manage").hide();
                    }
                } else {
                    // 表示不是管理员
                    $("#user").show();
                    $("#manage").hide();
                    // 是否预约
                    if (isBook === 0){
                        // 已预约
                        $("#one-user").hide();
                        $("#tow-user").show();
                        $("#three-user").hide();
                        $("#four-user").hide();
                        // 是否评价
                        if (isEvaluation === 0){
                            // 已评价
                            $("#one-user").hide();
                            $("#tow-user").hide();
                            $("#three-user").hide();
                            $("#four-user").show();
                        } else {
                            // 未评价
                            $("#one-user").hide();
                            if (isPastDue()) {
                                $("#tow-user").show();
                                $("#three-user").hide();
                            }else {
                                $("#tow-user").hide();
                                $("#three-user").show();
                            }
                            $("#four-user").hide();
                        }
                    } else {
                        // 未预约
                        $("#one-user").show();
                        $("#tow-user").hide();
                        $("#three-user").hide();
                        $("#four-user").hide();
                    }
                }

            }
        });
    }

    // ----------判断服务是否结束----------
    function isPastDue() {

        var timestamp;
        if (isIOS()){
            // ios 系统
            // 班车发车时间
            console.log($departureDateTime.text().replace(/\-/g, '/'));
            timestamp = new Date($departureDateTime.text().replace(/\-/g, '/')).getTime();
            console.log(timestamp);
            // 服务器的当前时间
            console.log(new Date(serviceDateTime).getTime());
            return timestamp > serviceDateTime;
        } else {
            // 安卓或其他的系统
            // 班车发车时间
            console.log($departureDateTime.text());
            timestamp = new Date($departureDateTime.text()).getTime();
            console.log(timestamp);
            // 服务器的当前时间
            console.log(new Date(serviceDateTime).getTime());
            return timestamp > serviceDateTime;
        }

    }

    // ----------获取服务器时间“yyyy-MM-dd HH:mm:ss”----------
    function getServiceDateTime() {

        $.ajax({
            type : "post",
            url : "/bcs/manage/getServiceCurrentDateTime",
            async : false,
            success : function(result){
                if (result.manageResult.errcode === 0){

                    serviceDateTime = result.manageResult.data;
                    console.log(serviceDateTime);
                }
            }
        });
    }

    // -------------获取url中的参数----------------
    function getUrlParam() {
        var url = window.location.href;
        console.log(url);
        if(url.indexOf("?") === -1) {
            return null;
        }
        var urlSplit = url.split("?")[1];
        if(urlSplit.indexOf("&") === -1) {
            var arr1 = urlSplit.split("=");
            return arr1[1];
        }
    }

});
